// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#include <pollux/testing/gtest_utils.h>

#include <cpr/cpr.h>
#include <map>

class CprHttpClientTest : public testing::Test {};

// This test requires open access to internet and most places test runners might
// be closed off from the general internet. And this test case is just an
// illustration of how to use cpr, so disable it by default.
TEST_F(CprHttpClientTest, DISABLED_basic) {
  auto response = cpr::Get(
      cpr::Url{"https://facebookincubator.github.io/pollux/"},
      cpr::Timeout{std::chrono::seconds{3}});
  ASSERT_EQ(response.status_code, 200);
  ASSERT_FALSE(response.text.empty());

  response = cpr::Get(cpr::Url{"null"});
  ASSERT_NE(response.status_code, 200);
  ASSERT_TRUE(response.text.empty());

  response = cpr::Post(
      cpr::Url{"https://facebookincubator.github.io/pollux/"},
      cpr::Body{"select * from nation limit 1"},
      cpr::Header({{"Content-Type", "text/plain"}}));
  ASSERT_EQ(response.status_code, 405);
  ASSERT_FALSE(response.text.empty());

  response = cpr::Post(
      cpr::Url{"null"},
      cpr::Body{"select * from nation limit 1"},
      cpr::Header({{"Content-Type", "text/plain"}}));
  ASSERT_NE(response.status_code, 200);
  ASSERT_TRUE(response.text.empty());
}
